<?php
class Application_Model_DbTable_User extends Zend_Db_Table_Abstract{
	protected $_primary = 'user_id';
	protected $_name = 'tbl_user';
	protected $_referenceMap = array (
			'tbl_manufacture' => array (
					'columns' => array('user_group_user_id'),
					'refTableClass' => 'Application_Model_DbTable_GroupUser'
			),
			
	);
	
	public function getList($filters = array(),$sortType = "ASC",$sortBy = null){
			$select = $this->select();					
			if( count($filters) > 0 ){				
				foreach($filters as $key => $value){
					if($key=='keyword' && trim($value)!=''){
						$select->where("user_username like '%$value%' OR user_email like '%$value%'
								OR user_fullname like '%$value%'
								");
			
					}
					if($key=='group' && $value!=0){
						$select->where('user_group_user_id = ?',$value);
					}
					if($key=="fromDate" && $value!=null){
						$select->where('user_creation_time >= ?',$value);
					}
					if($key=="toDate" && $value!=null){
						$select->where('user_creation_time <= ?',$value);
					}
					if($key=="status" && ($value=="0" || $value=="1")){
						$select->where('user_status = ?',$value);
					}
				}
			}
			
			if($sortBy==null){
				$sortBy = "user_creation_time";
				$sortType = "Desc";
			}
			$select->order($sortBy . " " . $sortType);
			 
			return $result = $this->fetchAll($select);
	}

}